package com.idopartx.phonelightning.ui.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.idopartx.phonelightning.R
import com.google.android.material.switchmaterial.SwitchMaterial
import com.idopartx.phonelightning.entity.AppInfo

class AppListAdapter : BaseQuickAdapter<AppInfo, BaseViewHolder>(R.layout.adapter_app_list) {

    override fun convert(holder: BaseViewHolder, item: AppInfo) {

        holder.setImageBitmap(R.id.iv_icon, item.icon)
        holder.setText(R.id.tv_title, item.name)

        holder.getView<SwitchMaterial>(R.id.switch_delete).apply {
            isChecked = item.isOpen ?: false


            setOnClickListener {
                item.isOpen = !(item.isOpen ?: false)
            }

        }


    }

    fun getSelectList(): MutableList<String> {
        val selectList = arrayListOf<String>()
        data.forEach {
            if (it.isOpen == true) {
                selectList.add(it.packageName ?: "")
            }
        }
        return selectList
    }
}